package day05;
import java.util.Arrays;
public class ArrayDemo {
    public static void main(String[] args) {
        //5)数组的排序
        int[] arr = new int[10];
        for (int i=0;i<arr.length;i++){
            arr[i] = (int) (Math.random()*100);
            System.out.println(arr[i]);
        }

        Arrays.sort(arr); //对arr数组做升序排列

        System.out.println("排序后:");
        for (int i=0;i<arr.length;i++){
            System.out.println(arr[i]);
        }

        System.out.println("降序输出...");
        for (int i=arr.length-1;i>=0;i--){
            System.out.println(arr[i]);
        }

        /*
        //4)数组的遍历:
        int[] arr = new int[10];
        for (int i=0;i<arr.length;i++){
            arr[i] = (int)(Math.random()*100);
            System.out.println(arr[i]);
        }
         */

        /*
        int[] a = new int[5];
        double[] d = new double[10];
        boolean[] b = new boolean[25];

        //2)数组的初始化:-------初始化数组中的元素
        int[] arr1 = new int[3];
        int[] arr2 = {2,5,8};
        int[] arr3 = new int[]{2,5,8};
        int[] arr4;
        //arr4 = {2,5,8}; //编译错误，此方式只能声明同时初始化
        arr4 = new int[]{2,5,8};

        //3)数组的访问:------访问的是数组中的元素
        int[] arr = new int[3];
        System.out.println("数组的长度:"+arr.length);
        System.out.println(arr[0]);
        arr[0] = 100;
        arr[1] = 200;
        arr[2] = 300;
        //arr[3] = 400; //运行时会发生数组下标越界异常
        System.out.println(arr[arr.length-1]);
         */
    }
}
